﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FinanSoft.BusinessLayer;
using FinanSoft.Utilities;

namespace FinanSoft
{
    public partial class frmLogin : Form
    {
        frmAbrirComp frmPadre;

        public frmLogin(frmAbrirComp frmPadre_)
        {
            frmPadre = frmPadre_;
            InitializeComponent();
        }

        private void btnIngresar_Click(object sender, EventArgs e)
        {
            UserManager manager = UserManager.GetInstance();
            String username = textUsername.Text;
            String password = textPassword.Text;

            Constants.ValidationCode code = manager.LoginUser(username, password);

            if (code.Equals(Constants.ValidationCode.LoginSucceeded))
            {
                // Cargamos y mostramos el formulario Principal
                frmPrincipal frmPrincipalV = new frmPrincipal();
                frmPrincipalV.ShowDialog(this);     // Mostramos el formulario de forma modal.
                //frmPrincipalV.Dispose();
                frmPadre.Close();
                Close();
            }
            else
                MessageBox.Show(manager.ErrorMessage, MessageConstants.TITLE, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void textUsername_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
